<template>
    <div class="e-form">
        <BillTop @cancel="handleClose"></BillTop>
        <div class="tabs warningTabs">
            <el-tabs
                tab-position="left"
                v-model="tabsName"
                @tab-click="onChangeTab"
            >
                <el-tab-pane
                    label="基本信息"
                    name="baseInfo"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="调拨明细"
                    name="detailed"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="附件信息"
                    name="attach"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
  <el-tab-pane
                    label="审核历史"
                    name="auditHistory"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <div>
                    <div id="baseInfoCon" class="con">

                        <div class="tabs-title" id="baseInfo">基本信息</div>
                        <div style="width: 100%" class="form">
                            <el-form :model="basicForm" :label-width="formLabelWidth">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="调拨编号：">
                                    <span>{{ basicForm.billNo }}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                               <el-form-item label="机构：">
                                    <span>{{ basicForm.orgName }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="调入机构：">
                                     <span>{{ basicForm.transferInOrgName }}</span>
                                </el-form-item>
                            </el-col>

                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                  <el-form-item label="调拨日期：">
                                      <span>{{ basicForm.allotDate }}</span>

                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="接收人员：">
                                <span>
                                    {{
                                        basicForm.receiverName
                                    }}
                                </span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                 <el-form-item label="调拨金额（元）：">
                                   <span>
                                       {{basicForm.allotAmount}}
                                   </span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">

                                    <el-form-item label="发货人员：">
                                 <span>

                                       {{basicForm.senderName}}
                                   </span>
                                </el-form-item>
                            </el-col>
                        </el-row>

                                <el-row>
                                     <el-col :span="12">
                                        <el-form-item label="调拨数量：">
                                            <span>
                                                {{ basicForm.allotQuantity }}
                                            </span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="币种：">
                                    <span>{{basicForm.currency}}</span>

                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="人民币汇率：">
                                    <span>{{ basicForm.rmbRate }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                          <el-row>
                            <el-col :span="24">
                                <el-form-item label="备注：">
                                    <span>
                                        {{
                                            basicForm.remarks
                                        }}
                                    </span>

                                </el-form-item>
                            </el-col>
                        </el-row>
                         <el-row>
                            <el-col :span="12">
                                <el-form-item label="本位币：">
                                    <span>{{ basicForm.baseCurName }}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="本位币汇率：">
                                    <span>{{
                                        basicForm.baseCurRate
                                    }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                         <el-row>
                            <el-col :span="12">
                                <el-form-item label="状态：">
                                    <span>{{ stateArr[basicForm.state] }}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="调拨金额（本位币）：">
                                    <span>{{
                                        basicForm.baseCurRate
                                    }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    <el-row>
                        <el-form-item label="冲红单" v-if="isRedSingle"
                            ><span :style="redBillStateStyle">{{
                                redBillStateFun
                            }}</span></el-form-item
                        >
                    </el-row>
<el-row v-if="basicForm.state === 5">
                                        <el-col :span="12">
                                        <el-form-item label="作废人：">
                                            <span>{{ basicForm.nullifyCreator }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="作废原因：">
                                            <span>{{basicForm.nullifyReason }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row v-if="basicForm.state === 5">
                                    <el-col :span="12">
                                        <el-form-item label="作废说明：">
                                            <span>{{
                                                basicForm.nullifyDescription
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                        <el-col :span="12">
                                        <el-form-item label="作废时间：">
                                            <span>{{
                                                basicForm.nullifyCreated
                                            }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                    </el-form>
                        </div>
                    </div>
                    <!-- 调拨明细 -->
                    <div id="detailedCon" class="con">
                        <div class="tabs-title" id="detailed">调拨明细</div>
                        <div class="e-table">
                             <div class="errorMsg" v-if="errorMsg.length > 0">
                                <span
                                    v-for="(item, index) in errorMsg"
                                    :key="index"
                                >
                                    {{ item }}
                                </span>
                            </div>
                              <el-table
                                :data="detailedTableData"
                                border
                                style="width: 100%"
                                 default-expand-all
                                :header-cell-style="{ textAlign: 'center' }"
                                :cell-style="{ textAlign: 'center' }"
                                :tree-props="{
                                    children: 'children',
                                    hasChildren: 'hasChildren'
                                }"
                                ref="multipleTable"
                                 v-sortTable="{ 'multipleTable': tableData, '_this': this, 'ref': 'table' }"
                                row-key="uuid"
                                 :row-class-name="tableRowClassName"
                                 :max-height="$store.state.tableHeight"
                            >
                                <el-table-column
                                    label="操作"
                                    fixed
                                    width="100px"
                                    align="left"
                                >

                                </el-table-column>
                                <el-table-column
                                    prop="materialClassName"
                                    label="类别"
                                    mini-width="300"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="materialName"
                                    label="物资名称"
                                    width="200"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="spec"
                                    label="规格"
                                    width="200"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="unit"
                                    label="计量单位"
                                    width="200"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="texture"
                                    label="材质"
                                    width="200"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="allocationQuantity"
                                    label="调拨数量"
                                    width="200"
                                >
                                 <template slot-scope="{ row, $index }">
                                      <span v-if="isRedSingle">
                                            {{
                                                row.allocationQuantity
                                            }}
                                        </span>
                                        <el-input
                                            v-enter-integer1="{
                                                set: row,
                                                key: 'allocationQuantity'
                                            }"
                                            @input="curStateChange(row)"
                                            v-model="row.allocationQuantity"
                                            clearable
                                            v-if="$index > 0&&!isRedSingle"
                                        ></el-input>
                                    </template>
                                </el-table-column>
                                 <el-table-column
                                    prop="price"
                                    label="成本单价"
                                    width="200"
                                >
                                </el-table-column>
                                     <el-table-column
                                    prop="money"
                                    label="成本金额"
                                    width="200"
                                >
                                <template slot-scope="{row,$index}">
                                    <span v-if="$index>0">
                                        {{
                                            row.money
                                        }}
                                    </span>
                                </template>
                                </el-table-column>
                            </el-table>
                            <ComPagination />
                        </div>
                    </div>
                    <!-- 附件信息 -->
                    <div id="attachCon" class="con">
                        <div class="tabs-title" id="attach">照片信息</div>
                     <attach-comp :relationId="attachId" bucketName="turnover" isView/>

                    </div>
                        <!-- 审核历史 -->
                    <div id="auditHistoryCon" class="con">
                        <div class="tabs-title" id="auditHistory">审核历史</div>
                        <div class="e-table">
                             <ComAuditHistoryIndex
                                :billType="6071"
                                ref="AuditHistoryRef"
                            />
                        </div>
                    </div>
                </div>
            </el-tabs>
        </div>
          <div class="buttons" v-if="!isview">
            <el-button
                type="primary"
                style="background: #2e61d7"
                v-if="
                    basicForm.state == 2 &&
                    basicForm.redState < 1
                "
                @click="redSingle"
                >冲红单</el-button
            >
              <ComExaButtons :auditState="auditState" :state="basicForm.state" @exas="exas" :founderId="basicForm.founderId" />
            <el-button size="small" @click="handleClose">取消</el-button>
        </div>
        <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
    </div>
</template>

<script>
import ComPagination from '@/components/pagination/pagination.vue'
import AttachComp from '@/components/common/attachIndex'
import {  mapState } from 'vuex'
import { getRmbRate } from '@/api/equip/common.js'
import { selectOrgRole, selectgetUserUnderOrgPage } from '@/api/turnover/ppw.js'
import ComAuditHistoryIndex from '@/pages/revolveMaterialManage/components/auditHistory/auditHistoryIndex'
import { getUuid,  } from '@/utils/common'
import ComExaButtons from '@/components/common/exaButtons'
import { exas } from '@/pages/revolveMaterialManage/common/revolveCom.js'

import auditRequest from '@/api/turnover/audit.js'
import { mapMutations } from 'vuex'

import otherRequest from '@/api/turnover/other.js'

import $ from 'jquery'
import '@/utils/jquery.scrollTo.min'
export default {
    components: {
        ComPagination, AttachComp, ComAuditHistoryIndex, ComExaButtons
    },
    computed: {
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        }, attachId () {
            return this.billId
        },
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm, //币种
            timeUnitList: state => state.equip.equipData.timeUnitList //计时单位
        }),
        statusLable () {
            return param => {
                const state = this.$store.state.equip.equipData.state
                const obj = state.find(x => x.value === param)
                if (obj !== undefined) {
                    return obj.label
                }
            }
        },

        // 红单状态
        redBillStateFun () {
            let redState = ''
            switch (this.basicForm.redState) {
            case 0:
                redState = '冲销中'
                break
            case 1:
                redState = '冲销中'
                break
            case 2:
                redState = '已冲销'
                break
            case 3:
                redState = '红单'
                break
            }
            return redState
        }
    },
    watch: {
        //给错误标签加上提醒
        errorList: newData=>{
            const tabs = document.querySelectorAll('.el-tabs__item')
            tabs.forEach(DOM=>{
                const { childNodes } = DOM
                if(childNodes.length > 1) {
                    DOM.removeChild(childNodes[1])
                }
            })
            newData.forEach(item=>{
                const itemDom = document.querySelector(`#tab-${item}`)
                var element = document.createElement('i')
                element.className = 'el-icon-warning-outline warning'
                itemDom.appendChild(element)
            })
        },
    },
    mounted () {
        this.getLastConHeight()
        // 保存所有tabName
        const arr = ['baseInfo', 'detailed', 'attach', 'auditHistory']
        this.tabArr = arr  //标星星

        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const itemTop = document.getElementById(item).offsetTop
                    return itemTop
                })
            }
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if ((scrollTop + 1) >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight

        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight

            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item).offsetTop
                return itemTop
            })
        })
        this.scorllDtl()

    },
    created () {
        if (
            this.$route.query.isview === 'true' ||
            this.$route.query.isview === 'false'
        ) {
            this.isview = JSON.parse(this.$route.query.isview)
        }
        this.billId = this.$route.query.billid
        this.getBasicInfo()
        this.getUserInfo()
        this.getCurrentUnitInfo()
        this.getDtlList()
    },
    data () {
        return {
            tabsName: 'baseInfo',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            basicForm: {
                'allotAmount': 0,
                'allotDate': '',
                'allotQuantity': 0,
                'baseCurAllotAmount': 0,
                'baseCurId': '',
                'baseCurName': '',
                'baseCurRate': 0,
                'billId': '',
                'billNo': '',
                'currency': '',
                'currencyId': '',
                'hasRed': 0,
                'isRed': 0,
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'parentId': '',
                'receiverId': '',
                'receiverName': '',
                'remarks': '',
                'rmbId': '',
                'rmbName': '',
                'rmbRate': 0,
                'senderId': 0,
                'senderName': 0,
                'sourceId': '',
                'sourceNumber': '',
                'state': 0,
                'transferInOrgId': '',
                'transferInOrgName': '',
                'workId': ''
            },
            query: {
                limit: 10,
                number: '',
                orgname: '',
                page: 1,
                states: [],
            },
            isview: false,

            formLabelWidth: '150px',
            detailedTableData: [], //物资明细
            changeTableData: [], //变更信息
            basicInfo: {},
            stateArr: ['草稿', '审核中', '已审核', '已作废'],
            MouseEnterId: 0,
            showBaseCurName: true,
            rules: {
                currencyId: [
                    {
                        required: true,
                        message: '请选择币种',
                        trigger: 'chenge'
                    }
                ],
                allotDate: [
                    {
                        required: true,
                        message: '请选择日期',
                        trigger: 'blur'
                    }
                ],
            },
            auditParams: {
                billId: this.$route.query.billid,

                billType: 6071,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            },
            nullifyParams: { //作废
                'billId': this.$route.query.billid,
                'billType': 6071,
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': ''
            },
            auditState: {},
            errorList: [], //控制导航栏感叹号的显示
            errorMsg: [],
            isErrorMsg: true, //是否提醒错误信息
            redBillStateStyle: {
                width: '300px',
                height: '30px',
                color: '#fff',
                backgroundColor: '#FF2300',
                'text-align': 'center'
            },
            isRedSingle: false

        }
    },
    methods: {
        //跳转到明细
        scorllDtl () {
            if(this.$route.query.name) {
                setTimeout(() => {
                    //因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                    let obj = {
                        name: this.$route.query.name
                    }
                    this.tabsName = this.$route.query.name
                    this.onChangeTab(obj)
                }, 200)
            }
        },
        onChangeTab (e) {
            const height  = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('recodesCon')) {
                    const lastConHeight = document.getElementById('recodesCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        getUserInfo () {
            const { baseCyByOrgId } = this.userInfo

            this.basicForm.baseCurName = baseCyByOrgId.currencyName  //本位币
            this.basicForm.baseCurId = baseCyByOrgId.currency
        },
        async clickOrg () {
            const data =  await selectOrgRole()
            this.basicForm.transferInOrgName = data.orgName
            this.basicForm.transferInOrgId = data.orgId
        },
        //机构下级接收用户
        async selectUnderOrgPage () {
            if(!this.basicForm.transferInOrgName) {
                this.clientPop('err', '请先选择调入机构！')
                return
            }
            const data =  await selectgetUserUnderOrgPage(this.basicForm.transferInOrgId)
            this.basicForm.receiverName = data.userName
            this.basicForm.receiverId = data.userId
        },
        //币种切换
        currencyChange (val) {
            this.basicForm.currency = this.currencyForm.find(
                x => x.value === val
            ).label //币种
            if (this.basicForm.currency === '人民币') {
                this.basicForm.rmbRate = 1
            } else {
                getRmbRate({
                    //获取机构下某币种的人民币汇率
                    currency: val,
                    orgId: this.userInfo.orgInfo.orgId
                })
                    .then(res => {
                        this.basicForm.rmbRate = res.rate
                    })
                    .catch(() => {})
            }
            if (this.basicForm.currencyId === this.basicForm.baseCurId) {
                //币种=本位币
                this.basicForm.baseCurRate = 1
                this.showBaseCurName = false
            } else {
                this.basicForm.baseCurRate = null
                this.showBaseCurName = true
            }
        },
        getBasicInfo () {
            this.$Ajax
                .httpGet({
                    url: '/turnover/allocation/findById',
                    params: {
                        billId: this.billId
                    },
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                .then(res => {
                    res.redState === 3 ? this.isRedSingle = true : this.isRedSingle = false

                    for (let key in res) {
                        this.basicForm[key] = res[key]
                    }
                })
        },
        getCurrentUnitInfo () {
            auditRequest.getCurrentUnitInfo(this.auditParams).then(res => {
                this.auditState = res
            })
        },
        getDtlList () {
            otherRequest.turnoverAllocationFindByBillId(this.billId).then(res=>{
                if (res.length > 0) {
                    res.forEach(item => {
                        item.materialClassName = item.topClassName
                        item.uuid = getUuid()
                        item.children.forEach(i => {
                            i.parentId = item.uuid
                            i.uuid = i.dtlId
                            i.changeType = 0
                        })

                        const count = item.children.reduce(
                            (prev, c) => (prev += c.money || 0),
                            0
                        )
                        item.materialName = `小计： ${count}`
                    })

                    this.detailedTableData = res
                    this.upCount()
                }
            })
        },
        //更新基本信息
        updateBaseInfo () {
            return new Promise((resolve, reject)=>{
                otherRequest.turnoverAllocationUpdate(this.basicForm).then(()=>{
                    this.getBasicInfo() //更新基本信息
                    resolve()
                }).catch(err=>{
                    this.setError('baseInfo')
                    reject(err)
                })
                // this.$refs.ruleForm.validate(valid => {
                //     if (valid) {
                //         otherRequest.turnoverAllocationUpdate(this.basicForm).then(()=>{
                //             this.getBasicInfo() //更新基本信息
                //             resolve()
                //         }).catch(err=>{
                //             this.setError('baseInfo')
                //             reject(err)
                //         })
                //     }
                //     else {
                //         this.setError('baseInfo')
                //         this.scorllError()
                //         return false
                //     }
                // })
            })
        },
        //更新计划明细
        updateBudgetDtl () {
            if(this.detailedTableData.length > 0) {
                this.detailedTableData[0].businessType = this.basicForm.businessTypeKey
            }
            return new Promise((resolve, reject)=>{
                this.verifyTable().then(()=>{
                    otherRequest.turnoverAllocationUpdateDtlList(this.detailedTableData).then(()=>{
                        this.getDtlList() //更新明细
                        resolve()
                    }).catch(err=>{
                        this.setError('detailed')
                        reject(err)
                    })
                }).catch(err=>{
                    this.setError('detailed')
                    reject(err)
                    this.scorllError()
                })
            })
        },
        /**
         * 下边几个按钮
         */

        // 审核相关操作
        ...mapMutations(['setAuditParams']),

        // async exas (arg) {
        //     if (arg === 'audit') { //审核

        //         // // 明细非空验证
        //         this.errorList = []
        //         Promise.all([
        //             this.updateBaseInfo(),
        //             this.updateBudgetDtl(),
        //         ]).then(() => {
        //             this.setAuditParams(this.auditParams)
        //             // 客户端弹窗弹出本地页面
        //             openAppClient('/exaDialog', '填写审核意见', () => {
        //                 const auditParams = JSON.parse(localStorage.vuex).auditParams
        //                 auditRequest.audit(auditParams).then(() => {
        //                     this.clientPop('suc', '操作成功', this.handleClose)

        //                 })
        //             })
        //         })

        //     } else if (arg === 'undoAudit') { //撤销审核
        //         auditRequest.undoAudit(this.auditParams).then(() => {
        //             this.clientPop('suc', '撤回成功', this.handleClose)

        //         })
        //     } else if (arg === 'nullify') { //作废

        //         //作废
        //         this.setAuditParams(this.nullifyParams)
        //         // 客户端弹窗弹出本地页面
        //         openAppClient('/nullifyDialog', '单据作废原因', () => {
        //             const auditParams = JSON.parse(localStorage.vuex).auditParams
        //             auditRequest.nullify(auditParams).then(() => {
        //                 this.clientPop('suc', '作废成功', this.handleClose)
        //             })
        //         })
        //     } else if (arg === 'deleteData') { //删除按钮
        //         this.clientPop(
        //             'info',
        //             '确定要删除吗？删除的数据可以在【回收站】还原或彻底删除。',
        //             this.delData
        //         )
        //     }
        // },
        async exas (arg) {
            const requestFn = ()=>{
                return [
                    this.updateBaseInfo(),
                    this.updateBudgetDtl(),
                ]
            }
            exas(arg, this, requestFn)
        },
        // 点击冲红单
        redSingle () {
            this.$router.replace({
                path: '/revolveAllocationAdd',
                query: { isRedSingle: '1', billid: this.billId }
            })
        },

        upCount () {
            this.basicForm.allotAmount = 0
            this.basicForm.allotQuantity = 0
            if (this.detailedTableData.length > 0) {
                this.detailedTableData.forEach(v => {
                    v.children.forEach(item => {
                        if (v.changeType != -1 && item.money !== null) {
                            this.basicForm.allotAmount += Number(item.money)
                            this.basicForm.allotQuantity += Number(item.allocationQuantity)
                        }
                    })
                    const count = v.children.reduce(
                        (prev, c) => (prev += Number(c.money) || 0),
                        0
                    )
                    v.materialName = `小计： ${count}`
                })
            }
        },
        //判断当前状态是否已修改
        curStateChange (row) {
            this.curRow = row
            if (row.changeType !== 1) {
                {
                    this.curRow.changeType = 2
                }
            }

            // 计算剩余库存数量
            if(row.allocationQuantity) {
                row.money = row.allocationQuantity * row.price
            }
            this.upCount()
        },
        //点击删除的时候
        deleteEle (row) {
            row.changeType = -1
        },
        // 处理树
        tableRowClassName ({ row }) {
            if (row.children) {
                return 'warning-row'
            } else if (row.changeType === -1) {
                return 'row-hide'
            } else {
                return 'row-show'
            }
        },
        //设置错误标签
        setError (name) {
            if (!this.errorList.find(x => x === name)) {
                this.errorList.push(name)
            }
        },
        //跳转到第一个错误标签
        scorllError () {
            let num = this.tabArr.length
            this.errorList.forEach(item => {
                let index = this.tabArr.findIndex(x => x === item)
                num = index < num ? index : num
            })
            const obj = { name: this.tabArr[num] }
            this.tabsName = this.tabArr[num]
            this.onChangeTab(obj)
        },
        //计划明细非空验证
        verifyTable () {
            return new Promise((resolve, reject)=>{

                this.errorMsg = []
                this.detailedTableData.forEach(v => {
                    v.children.forEach((item, index) => {
                        if (item.changeType !== -1) {
                            if (item.allocationQuantity === '' || item.allocationQuantity === null) {
                                let str = `请填写第 ${index + 1} 行的调拨数量`
                                this.errorMsg.push(str)
                            }
                        }
                    })
                })

                if (this.errorMsg.length > 0) {
                    this.isErrorMsg = true
                    reject()

                } else {
                    this.isErrorMsg = false
                    resolve()

                }
            })

        },
        handleClose () {
            this.$router.push('/revolveAllocationList')
        },

    }
}
</script>

<style lang="scss" scoped>
.e-table {
    min-height: auto;
    background: #fff;
}
.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

::v-deep.el-input--suffix .el-input__inner {
    padding-right: 5px;
}
::v-deep.el-table .cell {
    text-align: center;
}
#iconEdit:hover {
  color: red;
}

.like {
  color: rgb(46, 97, 215);
  font-size: 17px;
  line-height: 30px;
  cursor: pointer;
}
</style>
